﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.ServiceModel.DomainServices.Client;
using Common = ClientSide.Common;
using Request = ServerSide.Requests;
using ServerSide.Common.Requests;
using System.ComponentModel.Composition;
using ClientSide.Common;

namespace Forms
{
    [Export(typeof(IPage))]
    public partial class Test : UserControl, IPage
    {
        public Test()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Request.HelloRequest req = new Request.HelloRequest();

            req.Name = "hasan";

            Common.Helpers.RequestSender.SendRequest(req, typeof(Request.HelloRequestResult), (s, ev) =>
            {
                Request.HelloRequestResult res = (Request.HelloRequestResult)s;
                MessageBox.Show("şimdilik oldu" + res.HelloString);
            }, null);
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            Request.MeyvelistesiRequest req = new Request.MeyvelistesiRequest();
            req.meyvesayisi = 15;
            Common.Helpers.RequestSender.SendRequest(req, typeof(Request.MeyveListesiResult), (s, ev) =>
            {
                Request.MeyveListesiResult res = (Request.MeyveListesiResult)s;
                dataGrid1.ItemsSource = res.meyveListesi;
            }, null);
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            LoginUserRequest req = new LoginUserRequest();
            req.UserName = "fakan";
            req.Password = "deneme";
            Common.Helpers.RequestSender.SendRequest(req, typeof(LoginUserResult), (s, ev) =>
            {
                LoginUserResult res = (LoginUserResult)s;
                if (!res.IsLoggedIn)
                {
                    MessageBox.Show("Giriş yapılamadı");
                }
                else
                {
                    MessageBox.Show("Hoşgeldiniz " + res.FirstName);
                }
            }, null
                );
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            LogoutUserRequest request = new LogoutUserRequest();

            Common.Helpers.RequestSender.SendRequest(request, typeof(LogoutUserResult),
                //Response Action
                (resultObject, eventArg) =>
                {
                    LogoutUserResult result = (LogoutUserResult)resultObject;
                    //TODO: LogoutUserResult UI operations
                },
                //Error Action
                (errorMessage, eventArg) =>
                {
                    MessageBox.Show(errorMessage.ToString());
                }
                );
        }

        public UIElement Container
        {
            get;
            set;
        }

        public string PageFileName
        {
            get;
            set;
        }

        public string PageHeader
        {
            get;
            set;
        }
    }
}
